﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using WinHBM.Core.Net.Http;
using WinHBM.Core.DB;
using WinHBM.Utils;

namespace WinHBM.Core.Net.Sockets.Cmd
{
    class GetFlowerRankCmd : SocketCmd
    {

        private static readonly log4net.ILog Logger = log4net.LogManager.GetLogger(typeof(LogCmd));

        private HttpClient client = HttpClient.Instance;

        public override void executeCmd(JObject request, FlashSocketServer socket)
        {
            SQLiteHelper db = SQLiteHelper.Instance;
            UserInfo user = UserInfo.INSTANCE;
            List<Dictionary<string, string>> list = db.find("babyInfo", UtilDict.make<string, string>("classId",user.ClassId+""));
            JArray arr = JArray.FromObject(list);
            JObject obj = new JObject();
            obj["contents"] = arr;
            socket.Send(wrapCmd(CMD_GETFLOWERRANK, obj["contents"].ToString()));
            //socket.Send(wrapCmd(CMD_GETFLOWERRANK, "[{\"id\": \"1\",\"class_id\": \"1\",\"name\": \"小呗\",\"red\": \"479\",\"avatar\": \"F:\\gl\\IMG_20160607.jpg\"}]"));
            //client.CreateRequest("/api/baby-top/list", RequestMethod.POST).send((respnse, data) =>
            //{
            //    Console.WriteLine(data["contents"].ToString());
            //    socket.Send(wrapCmd(CMD_GETFLOWERRANK, data["contents"].ToString()));
            //}, (response, exception) =>
            //{
            //    socket.Send(wrapCmd(CMD_GETFLOWERRANK, "请求失败"));
            //});
        }
    }
    }
